home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 7 / rzsz0589.zip / SZ.C < prev    next >
C/C++ Source or Header  |  1989-05-17  |  44KB  |  2,091 lines

  1. #define VERSION "sz 3.03 5-09-89"
  2. #define PUBDIR "/usr/spool/uucppublic"
  3.  
  4. /*% cc -compat -M2 -Ox -K -i -DTXBSIZE=16384  -DNFGVMIN -DREADCHECK sz.c -lx -o sz; size sz
  5.  
  6. /*% cc -Zi -DXX -DNFGVMIN -DREADCHECK sz.c -lx -o xsz; size xsz
  7. <-xtx-*> cc -Osal -DTXBSIZE=32768  -DSV sz.c -lx -o $B/sz; size $B/sz
  8.  
  9.  ****************************************************************************
  10.  *
  11.  * sz.c By Chuck Forsberg,  Omen Technology INC
  12.  *
  13.  ****************************************************************************
  14.  *
  15.  * Typical Unix/Xenix/Clone compiles:
  16.  *
  17.  *    cc -O sz.c -o sz        USG (SYS III/V) Unix
  18.  *    cc -O -DSV sz.c -o sz        Sys V Release 2 with non-blocking input
  19.  *                    Define to allow reverse channel checking
  20.  *    cc -O -DV7  sz.c -o sz        Unix Version 7, 2.8 - 4.3 BSD
  21.  *
  22.  *    cc -O -K -i -DNFGVMIN -DREADCHECK sz.c -lx -o sz    Classic Xenix
  23.  *
  24.  *    ln sz sb            **** All versions ****
  25.  *    ln sz sx            **** All versions ****
  26.  *
  27.  ****************************************************************************
  28.  *
  29.  * Typical VMS compile and install sequence:
  30.  *
  31.  *        define LNK$LIBRARY   SYS$LIBRARY:VAXCRTL.OLB
  32.  *        cc sz.c
  33.  *        cc vvmodem.c
  34.  *        link sz,vvmodem
  35.  *    sz :== $disk$user2:[username.subdir]sz.exe
  36.  *
  37.  *  If you feel adventureous, remove the #define BADSEEK line
  38.  *  immediately following the #ifdef vax11c line!  Some VMS
  39.  *  systems know how to fseek, some don't.
  40.  *
  41.  ****************************************************************************
  42.  *
  43.  *
  44.  * A program for Unix to send files and commands to computers running
  45.  *  Professional-YAM, PowerCom, YAM, IMP, or programs supporting Y/XMODEM.
  46.  *
  47.  *  Sz uses buffered I/O to greatly reduce CPU time compared to UMODEM.
  48.  *
  49.  *  USG UNIX (3.0) ioctl conventions courtesy Jeff Martin
  50.  *
  51.  *    This version implements ZMODEM Run Length Encoding, Comparision,
  52.  *    and variable length headers.  These features were not funded
  53.  *    by the original Telenet development contract.  This software,
  54.  *    including these features, may be freely used for non
  55.  *    commercial and educational purposes.  This software may also
  56.  *    be freely used to support file transfer operations to or from
  57.  *    licensed Omen Technology products.  Contact Omen Technology
  58.  *    for licensing for other uses.  Any programs which use part or
  59.  *    all of this software must be provided in source form with this
  60.  *    notice intact except by written permission from Omen
  61.  *    Technology Incorporated.
  62.  *
  63.  *        Omen Technology Inc        FAX: 503-621-3745
  64.  *        Post Office Box 4681
  65.  *        Portland OR 97208
  66.  *
  67.  *    Previous versions of this program (not containing the extensions
  68.  *    listed above) remain in the public domain.
  69.  *
  70.  *    This code is made available in the hope it will be useful,
  71.  *    BUT WITHOUT ANY WARRANTY OF ANY KIND OR LIABILITY FOR ANY
  72.  *    DAMAGES OF ANY KIND.
  73.  *
  74.  *  2.1x hacks to avoid VMS fseek() bogosity, allow input from pipe
  75.  *     -DBADSEEK -DTXBSIZE=32768  
  76.  *  2.x has mods for VMS flavor
  77.  *
  78.  * 1.34 implements tx backchannel garbage count and ZCRCW after ZRPOS
  79.  * in accordance with the 7-31-87 ZMODEM Protocol Description
  80.  */
  81.  
  82. #ifdef XX
  83. #define XARGSFILE "args"
  84. long Thisflen;
  85. #endif
  86.  
  87. char *substr(), *getenv();
  88.  
  89. #ifdef vax11c
  90. #define STATIC
  91. #define BADSEEK
  92. #define TXBSIZE 32768        /* Must be power of two, < MAXINT */
  93. #include <types.h>
  94. #include <stat.h>
  95. #define STAT
  96. #define LOGFILE "szlog.tmp"
  97. #include <stdio.h>
  98. #include <signal.h>
  99. #include <setjmp.h>
  100. #include <ctype.h>
  101. #include <errno.h>
  102. #define OS "VMS"
  103. #define ROPMODE "r"
  104. #define READCHECK
  105. #define BUFWRITE
  106. extern int errno;
  107. #define SS_NORMAL SS$_NORMAL
  108. #define xsendline(c) sendline(c)
  109.  
  110. #ifndef PROGNAME
  111. #define PROGNAME "sz"
  112. #endif
  113.  
  114.  
  115. #else    /* vax11c */
  116.  
  117. #ifdef GENIE
  118. #define STATIC static
  119. #define LOGFILE "szlog"
  120. #define BADSEEK
  121. #define TXBSIZE 32768        /* Must be power of two, < MAXINT */
  122. #define OS "GEnie"
  123. #define SS_NORMAL 0
  124. #include <stdio.h>
  125. #include <signal.h>
  126. #include <setjmp.h>
  127. #include <ctype.h>
  128. #include <errno.h>
  129. #include <stdlib.h>
  130. #include <fildes.h>
  131. FILDES fdes;
  132. extern int errno;
  133. int Binfile;
  134. long Thisflen;
  135.  
  136. #define sendline(c) putchar(c & 0377)
  137. #define xsendline(c) putchar(c)
  138.  
  139. #else    /* GENIE */
  140.  
  141. #define LOGFILE "/tmp/szlog"
  142. #define SS_NORMAL 0
  143. #include <stdio.h>
  144. #include <signal.h>
  145. #include <setjmp.h>
  146. #include <ctype.h>
  147. #include <errno.h>
  148. extern int errno;
  149. #define STATIC
  150.  
  151. #define sendline(c) putchar(c & 0377)
  152. #define xsendline(c) putchar(c)
  153.  
  154. #endif
  155. #endif
  156.  
  157. #define PATHLEN 256
  158. #define OK 0
  159. #define FALSE 0
  160. #ifdef TRUE
  161. #undef TRUE
  162. #endif
  163. #define TRUE 1
  164. #define ERROR (-1)
  165. /* Ward Christensen / CP/M parameters - Don't change these! */
  166. #define ENQ 005
  167. #define CAN ('X'&037)
  168. #define XOFF ('s'&037)
  169. #define XON ('q'&037)
  170. #define SOH 1
  171. #define STX 2
  172. #define EOT 4
  173. #define ACK 6
  174. #define NAK 025
  175. #define CPMEOF 032
  176. #define WANTCRC 0103    /* send C not NAK to get crc not checksum */
  177. #define WANTG 0107    /* Send G not NAK to get nonstop batch xmsn */
  178. #define TIMEOUT (-2)
  179. #define RCDO (-3)
  180. #define GCOUNT (-4)
  181. #define RETRYMAX 10
  182.  
  183.  
  184. #define HOWMANY 2
  185. STATIC int Zmodem=0;        /* ZMODEM protocol requested by receiver */
  186. unsigned Baudrate=4800;        /* Default, set by first mode() call */
  187. STATIC unsigned Effbaud = 4800;
  188. STATIC unsigned Txwindow;    /* Control the size of the transmitted window */
  189. STATIC unsigned Txwspac;    /* Spacing between zcrcq requests */
  190. STATIC unsigned Txwcnt;    /* Counter used to space ack requests */
  191. STATIC long Lrxpos;        /* Receiver's last reported offset */
  192. STATIC int errors;
  193.  
  194. #ifdef vax11c
  195. #include "vrzsz.c"    /* most of the system dependent stuff here */
  196. #else
  197. #ifdef GENIE
  198. #include "genie.c"    /* most of the system dependent stuff here */
  199. #else
  200. #include "rbsb.c"    /* most of the system dependent stuff here */
  201. #ifdef XX
  202. #undef STAT
  203. #endif
  204. #endif
  205. #endif
  206.  
  207. #include "crctab.c"
  208.  
  209. STATIC int Filesleft;
  210. STATIC long Totalleft;
  211.  
  212. /*
  213.  * Attention string to be executed by receiver to interrupt streaming data
  214.  *  when an error is detected.  A pause (0336) may be needed before the
  215.  *  ^C (03) or after it.
  216.  */
  217. #ifdef READCHECK
  218. STATIC char Myattn[] = { 0 };
  219. #else
  220. #ifdef USG
  221. STATIC char Myattn[] = { 03, 0336, 0 };
  222. #else
  223. #ifndef GENIE
  224. STATIC char Myattn[] = { 0 };
  225. #endif
  226. #endif
  227. #endif
  228.  
  229. FILE *in;
  230.  
  231. #ifdef BADSEEK
  232. STATIC int Canseek = 0;    /* 1: Can seek 0: only rewind -1: neither (pipe) */
  233. #ifndef TXBSIZE
  234. #define TXBSIZE 16384        /* Must be power of two, < MAXINT */
  235. #endif
  236. #else
  237. STATIC int Canseek = 1;    /* 1: Can seek 0: only rewind -1: neither (pipe) */
  238. #endif
  239.  
  240. #ifdef TXBSIZE
  241. #define TXBMASK (TXBSIZE-1)
  242. STATIC char Txb[TXBSIZE];        /* Circular buffer for file reads */
  243. STATIC char *txbuf = Txb;        /* Pointer to current file segment */
  244. #else
  245. STATIC char txbuf[1024];
  246. #endif
  247. STATIC long vpos = 0;            /* Number of bytes read from file */
  248.  
  249. STATIC char Lastrx;
  250. STATIC char Crcflg;
  251. STATIC int Verbose=0;
  252. STATIC int Modem2=0;        /* XMODEM Protocol - don't send pathnames */
  253. STATIC int Restricted=0;    /* restricted; no /.. or ../ in filenames */
  254. STATIC int Quiet=0;        /* overrides logic that would otherwise set verbose */
  255. STATIC int Ascii=0;        /* Add CR's for brain damaged programs */
  256. STATIC int Fullname=0;        /* transmit full pathname */
  257. STATIC int Unlinkafter=0;    /* Unlink file after it is sent */
  258. STATIC int Dottoslash=0;    /* Change foo.bar.baz to foo/bar/baz */
  259. STATIC int firstsec;
  260. STATIC int errcnt=0;        /* number of files unreadable */
  261. STATIC int blklen=128;        /* length of transmitted records */
  262. STATIC int Optiong;        /* Let it rip no wait for sector ACK's */
  263. STATIC int Eofseen;        /* EOF seen on input set by zfilbuf */
  264. STATIC int BEofseen;        /* EOF seen on input set by fooseek */
  265. STATIC int Totsecs;        /* total number of sectors this file */
  266. STATIC int Filcnt=0;        /* count of number of files opened */
  267. STATIC int Lfseen=0;
  268. STATIC unsigned Rxbuflen = 16384;    /* Receiver's max buffer length */
  269. STATIC int Tframlen = 0;    /* Override for tx frame length */
  270. STATIC int blkopt=0;        /* Override value for zmodem blklen */
  271. STATIC int Rxflags = 0;
  272. STATIC long bytcnt;
  273. STATIC int Wantfcs32 = TRUE;    /* want to send 32 bit FCS */
  274. STATIC char Lzconv;    /* Local ZMODEM file conversion request */
  275. STATIC char Lzmanag;    /* Local ZMODEM file management request */
  276. STATIC int Lskipnocor;
  277. STATIC char Lztrans;
  278. STATIC int Command;        /* Send a command, then exit. */
  279. STATIC char *Cmdstr;        /* Pointer to the command string */
  280. STATIC int Cmdtries = 11;
  281. STATIC int Cmdack1;        /* Rx ACKs command, then do it */
  282. STATIC int Exitcode;
  283. STATIC int Test;        /* 1= Force receiver to send Attn, etc with qbf. */
  284.             /* 2= Character transparency test */
  285. STATIC char *qbf=
  286.  "The quick brown fox jumped over the lazy dog's back 1234567890\r\n";
  287. STATIC long Lastsync;        /* Last offset to which we got a ZRPOS */
  288. STATIC int Beenhereb4;        /* How many times we've been ZRPOS'd same place */
  289.  
  290. STATIC jmp_buf tohere;        /* For the interrupt on RX timeout */
  291. STATIC jmp_buf intrjmp;    /* For the interrupt on RX CAN */
  292.  
  293. #ifdef XARGSFILE
  294. char *
  295. mystrsave(s)
  296. char *s;
  297. {
  298.     register char *p;
  299.     char *malloc();
  300.  
  301.     if (p = malloc(strlen(s)+1) ) {
  302.         strcpy(p, s); return p;
  303.     }
  304.     fprintf(stderr, "No memory for mystrsave!\n");
  305.     exit(1);
  306. }
  307.  
  308. /* Remove (presumably) terminating CR and/or LF from string */
  309. uncrlf(s)
  310. register char *s;
  311. {
  312.     for ( ; *s; ++s)
  313.         switch (*s) {
  314.         case '\r':
  315.         case '\n':
  316.             *s = 0;  return;
  317.         }
  318. }
  319. #endif
  320.  
  321.  
  322. /* called by signal interrupt or terminate to clean things up */
  323. bibi(n)
  324. {
  325.     canit(); fflush(stdout); mode(0);
  326.     fprintf(stderr, "sz: caught signal %d; exiting\n", n);
  327. #ifndef GENIE
  328.     if (n == SIGQUIT)
  329.         abort();
  330. #endif
  331.     if (n == 99)
  332.         fprintf(stderr, "mode(2) in rbsb.c not implemented!!\n");
  333.     cucheck();
  334.     exit(128+n);
  335. }
  336. /* Called when ZMODEM gets an interrupt (^X) */
  337. onintr()
  338. {
  339.     signal(SIGINT, SIG_IGN);
  340.     longjmp(intrjmp, -1);
  341. }
  342.  
  343. STATIC int Zctlesc;    /* Encode control characters */
  344. STATIC int Nozmodem = 0;    /* If invoked as "sb" */
  345. STATIC char *Progname = "sz";
  346. STATIC int Zrwindow = 1400;    /* RX window size (controls garbage count) */
  347. #include "zm.c"
  348.  
  349. #include "zmr.c"
  350.  
  351. #ifdef XARGSFILE
  352. #define XARGSMAX 256
  353. char *xargv[XARGSMAX+1];
  354. #endif
  355.  
  356. main(argc, argv)
  357. char *argv[];
  358. {
  359.     register char *cp;
  360.     register npats;
  361.     int dm;
  362.     char **patts;
  363.     static char xXbuf[BUFSIZ];
  364.  
  365.     if ((cp = getenv("ZNULLS")) && *cp)
  366.         Znulls = atoi(cp);
  367.     if ((cp=getenv("SHELL")) && (substr(cp, "rsh") || substr(cp, "rksh")))
  368.         Restricted=TRUE;
  369.     from_cu();
  370. #ifdef vax11c
  371.     chkinvok(PROGNAME);
  372. #else
  373.     chkinvok(argv[0]);
  374. #endif
  375.  
  376.     Rxtimeout = 600;
  377.     npats=0;
  378.     if (argc<2)
  379.         usage();
  380.     setbuf(stdout, xXbuf);        
  381.     while (--argc) {
  382.         cp = *++argv;
  383.         if (*cp++ == '-' && *cp) {
  384.             while ( *cp) {
  385.                 switch(*cp++) {
  386.                 case '\\':
  387.                      *cp = toupper(*cp);  continue;
  388.                 case '+':
  389.                     Lzmanag = ZMAPND; break;
  390. #ifdef CSTOPB
  391.                 case '2':
  392.                     Twostop = TRUE; break;
  393. #endif
  394.                 case 'a':
  395.                     Lzconv = ZCNL;
  396.                     Ascii = TRUE; break;
  397.                 case 'b':
  398.                     Lzconv = ZCBIN; break;
  399.                 case 'C':
  400.                     if (--argc < 1) {
  401.                         usage();
  402.                     }
  403.                     Cmdtries = atoi(*++argv);
  404.                     break;
  405.                 case 'i':
  406.                     Cmdack1 = ZCACK1;
  407.                     /* **** FALL THROUGH TO **** */
  408.                 case 'c':
  409.                     if (--argc != 1) {
  410.                         usage();
  411.                     }
  412.                     Command = TRUE;
  413.                     Cmdstr = *++argv;
  414.                     break;
  415.                 case 'd':
  416.                     ++Dottoslash;
  417.                     /* **** FALL THROUGH TO **** */
  418.                 case 'f':
  419.                     Fullname=TRUE; break;
  420.                 case 'e':
  421.                     Zctlesc = 1; break;
  422.                 case 'k':
  423.                     blklen=1024; break;
  424.                 case 'L':
  425.                     if (--argc < 1) {
  426.                         usage();
  427.                     }
  428.                     blkopt = atoi(*++argv);
  429.                     if (blkopt<24 || blkopt>1024)
  430.                         usage();
  431.                     break;
  432.                 case 'l':
  433.                     if (--argc < 1) {
  434.                         usage();
  435.                     }
  436.                     Tframlen = atoi(*++argv);
  437.                     if (Tframlen<32 || Tframlen>1024)
  438.                         usage();
  439.                     break;
  440.                 case 'N':
  441.                     Lzmanag = ZMNEWL;  break;
  442.                 case 'n':
  443.                     Lzmanag = ZMNEW;  break;
  444.                 case 'o':
  445.                     Wantfcs32 = FALSE; break;
  446.                 case 'p':
  447.                     Lzmanag = ZMPROT;  break;
  448.                 case 'r':
  449.                     if (Lzconv == ZCRESUM)
  450.                         Lzmanag = (Lzmanag & ZMMASK) | ZMCRC;
  451.                     Lzconv = ZCRESUM; break;
  452.                 case 'q':
  453.                     Quiet=TRUE; Verbose=0; break;
  454.                 case 't':
  455.                     if (--argc < 1) {
  456.                         usage();
  457.                     }
  458.                     Rxtimeout = atoi(*++argv);
  459.                     if (Rxtimeout<10 || Rxtimeout>1000)
  460.                         usage();
  461.                     break;
  462.                 case 'T':
  463.                     if (++Test > 1) {
  464.                         chartest(1); chartest(2);
  465.                         mode(0);  exit(0);
  466.                     }
  467.                     break;
  468. #ifndef vax11c
  469.                 case 'u':
  470.                     ++Unlinkafter; break;
  471. #endif
  472.                 case 'v':
  473.                     ++Verbose; break;
  474.                 case 'w':
  475.                     if (--argc < 1) {
  476.                         usage();
  477.                     }
  478.                     Txwindow = atoi(*++argv);
  479.                     if (Txwindow < 256)
  480.                         Txwindow = 256;
  481.                     Txwindow = (Txwindow/64) * 64;
  482.                     Txwspac = Txwindow/4;
  483.                     if (blkopt > Txwspac
  484.                      || (!blkopt && Txwspac < 1024))
  485.                         blkopt = Txwspac;
  486.                     break;
  487.                 case 'X':
  488.                     ++Modem2; break;
  489.                 case 'Y':
  490.                     Lskipnocor = TRUE;
  491.                     /* **** FALLL THROUGH TO **** */
  492.                 case 'y':
  493.                     Lzmanag = ZMCLOB; break;
  494.                 case 'Z':
  495.                 case 'z':
  496.                     Lztrans = ZTRLE;  break;
  497.                 default:
  498.                     usage();
  499.                 }
  500.             }
  501.         }
  502.         else if ( !npats && argc>0) {
  503.             if (argv[0][0]) {
  504.                 npats=argc;
  505.                 patts=argv;
  506.             }
  507.         }
  508.     }
  509.     if (npats < 1 && !Command && !Test) 
  510.         usage();
  511.     if (Verbose) {
  512.         if (freopen(LOGFILE, "a", stderr)==NULL) {
  513.             printf("Can't open log file %s\n",LOGFILE);
  514.             exit(0200);
  515.         }
  516.         setbuf(stderr, NULL);
  517.     }
  518.     if (Fromcu && !Quiet) {
  519.         if (Verbose == 0)
  520.             Verbose = 2;
  521.     }
  522.     vfile("%s %s for %s\n", Progname, VERSION, OS);
  523.  
  524. #ifdef XARGSFILE
  525.     vfile("npats=%d *patts=%s", npats, *patts);
  526.     if (npats == 1 && !strcmp(XARGSFILE, *patts)) {
  527.         in = fopen(XARGSFILE, "r");
  528.         if (!in) {
  529.             printf(stderr, "Can't open / control file!\n");
  530.             exit(2);
  531.         }
  532.         for (npats=0,argv=patts=xargv; npats<XARGSMAX; ++npats,++argv) {
  533.             if (fgets(txbuf, 1024, in) <= 0)
  534.                 break;
  535.             uncrlf(txbuf);
  536.             *argv = mystrsave(txbuf);
  537.         }
  538.         fclose(in);
  539.     }
  540. #endif
  541.  
  542.     mode(1);
  543.  
  544. #ifdef GENIE
  545.     signal(SIGINT, SIG_IGN);
  546. #else
  547.     if (signal(SIGINT, bibi) == SIG_IGN) {
  548.         signal(SIGINT, SIG_IGN); signal(SIGKILL, SIG_IGN);
  549.     } else {
  550.         signal(SIGINT, bibi); signal(SIGKILL, bibi);
  551.     }
  552. #endif
  553. #ifdef SIGQUIT
  554.     if ( !Fromcu)
  555.         signal(SIGQUIT, SIG_IGN);
  556. #endif
  557. #ifdef SIGTERM
  558.     signal(SIGTERM, bibi);
  559. #endif
  560.  
  561.     if ( !Modem2) {
  562.         if (!Nozmodem) {
  563.             printf("rz\r");  fflush(stdout);
  564.         }
  565.         countem(npats, patts);
  566.         if (!Nozmodem) {
  567.             stohdr(0L);
  568.             if (Command)
  569.                 Txhdr[ZF0] = ZCOMMAND;
  570.             zshhdr(4, ZRQINIT, Txhdr);
  571.         }
  572.     }
  573.     fflush(stdout);
  574.  
  575.     if (Command) {
  576.         if (getzrxinit()) {
  577.             Exitcode=0200; canit();
  578.         }
  579.         else if (zsendcmd(Cmdstr, 1+strlen(Cmdstr))) {
  580.             Exitcode=0200; canit();
  581.         }
  582.     } else if (wcsend(npats, patts)==ERROR) {
  583.         Exitcode=0200;
  584.         canit();
  585.     }
  586.     fflush(stdout);
  587.     mode(0);
  588.     dm = ((errcnt != 0) | Exitcode);
  589.     if (dm) {
  590.         cucheck();  exit(dm);
  591.     }
  592.     exit(SS_NORMAL);
  593.     /*NOTREACHED*/
  594. }
  595.  
  596. wcsend(argc, argp)
  597. char *argp[];
  598. {
  599.     register n;
  600.  
  601.     Crcflg=FALSE;
  602.     firstsec=TRUE;
  603.     bytcnt = -1;
  604.     if (Nozmodem) {
  605.         printf("Start your YMODEM receive. ");  fflush(stdout);
  606.     }
  607.     for (n=0; n<argc; ++n) {
  608.         Totsecs = 0;
  609.         if (wcs(argp[n])==ERROR)
  610.             return ERROR;
  611.     }
  612.     Totsecs = 0;
  613.     if (Filcnt==0) {    /* bitch if we couldn't open ANY files */
  614.         if (!Nozmodem && !Modem2) {
  615.             Command = TRUE;
  616.             Cmdstr = "echo \"sz: Can't open any requested files\"";
  617.             if (getnak()) {
  618.                 Exitcode=0200; canit();
  619.             }
  620.             if (!Zmodem)
  621.                 canit();
  622.             else if (zsendcmd(Cmdstr, 1+strlen(Cmdstr))) {
  623.                 Exitcode=0200; canit();
  624.             }
  625.             Exitcode = 1; return OK;
  626.         }
  627.         canit();
  628.         fprintf(stderr,"\r\nCan't open any requested files.\r\n");
  629.         return ERROR;
  630.     }
  631.     if (Zmodem)
  632.         saybibi();
  633.     else if ( !Modem2)
  634.         wctxpn("");
  635.     return OK;
  636. }
  637.  
  638. wcs(oname)
  639. char *oname;
  640. {
  641.     register c;
  642.     register char *p, *q;
  643. #ifdef STAT
  644.     struct stat f;
  645. #endif
  646.     char name[PATHLEN];
  647.  
  648.     strcpy(name, oname);
  649.  
  650. #ifdef XARGSFILE
  651.     /* Parse GEniename:REALname:length pathname syntax */
  652.     Thisflen = -1;
  653.     for (p = oname; *p; ++p) {
  654.         if (*p == ':') {
  655.             *p++ = 0;
  656.             q = p;
  657.             for (++p; *p; ++p) {
  658.                 if (*p == ':') {
  659.                     *p++ = 0;
  660.                     Thisflen = atol(p);
  661.                     break;
  662.                 }
  663.             }
  664.             strcpy(name, q);
  665.             break;
  666.         }
  667.     }
  668. #endif
  669.  
  670. #ifdef GENIE
  671.     _describe(oname,&fdes);        /* An undocumented goodie */
  672.     if (fdes.type_file == 1) {    /* Fortran Sequential Binary */
  673.         Binfile = 1;
  674.         in = fopen(oname,"rB");
  675.     }
  676.     else if (fdes.type_file == 0)  { /* Ascii */
  677.         Binfile = 0;
  678.         in = fopen(oname,"r");
  679.     }
  680.     else {                /* not a SL filetype */
  681.         fprintf(stderr, "\nUnknown file type %d\n",fdes.type_file);
  682.         ++errcnt;
  683.         return OK;        /* pass over it, there may be others */
  684.     }
  685. #else
  686.     if (Restricted) {
  687.         /* restrict pathnames to current tree or uucppublic */
  688.         if ( substr(name, "../")
  689.          || (name[0]== '/' && strncmp(name, PUBDIR, strlen(PUBDIR))) ) {
  690.             canit();
  691.             fprintf(stderr,"\r\nsz:\tSecurity Violation\r\n");
  692.             return ERROR;
  693.         }
  694.     }
  695.  
  696.     in=fopen(oname, ROPMODE);
  697. #endif
  698.  
  699.     if (in==NULL) {
  700.         ++errcnt;
  701.         return OK;    /* pass over it, there may be others */
  702.     }
  703.     BEofseen = Eofseen = 0;  vpos = 0;
  704.  
  705. #ifdef STAT
  706.     /* Check for directory or block special files */
  707.     fstat(fileno(in), &f);
  708.     c = f.st_mode & S_IFMT;
  709.     if (c == S_IFDIR || c == S_IFBLK) {
  710.         fclose(in);
  711.         return OK;
  712.     }
  713. #endif
  714.  
  715.     ++Filcnt;
  716.     switch (wctxpn(name)) {
  717.     case ERROR:
  718.         return ERROR;
  719.     case ZSKIP:
  720.         return OK;
  721.     }
  722. #ifdef STAT
  723.     if (!Zmodem && wctx(f.st_size)==ERROR)
  724.         return ERROR;
  725. #else
  726.     if (!Zmodem && wctx(1000000000L)==ERROR)
  727.         return ERROR;
  728. #endif
  729.  
  730. #ifndef vax11c
  731. #ifndef GENIE
  732.     if (Unlinkafter)
  733.         unlink(oname);
  734. #endif
  735. #endif
  736.  
  737.     return 0;
  738. }
  739.  
  740. /*
  741.  * generate and transmit pathname block consisting of
  742.  *  pathname (null terminated),
  743.  *  file length, mode time and file mode in octal
  744.  *  as provided by the Unix fstat call.
  745.  *  N.B.: modifies the passed name, may extend it!
  746.  */
  747. wctxpn(name)
  748. char *name;
  749. {
  750.     register char *p, *q;
  751.     char name2[PATHLEN];
  752. #ifdef STAT
  753.     struct stat f;
  754. #endif
  755.  
  756.     if (Modem2) {
  757. #ifdef STAT
  758.         if (*name && fstat(fileno(in), &f)!= -1) {
  759.             fprintf(stderr, "Sending %s, %ld XMODEM blocks. ",
  760.               name, (127+f.st_size)>>7);
  761.         }
  762. #endif
  763.         fprintf(stderr, "Give your local XMODEM receive command now.\r\n");
  764.         fflush(stderr);
  765.         return OK;
  766.     }
  767.     zperr("Awaiting pathname nak for %s", *name?name:"<END>");
  768.     if ( !Zmodem)
  769.         if (getnak())
  770.             return ERROR;
  771.  
  772.     q = (char *) 0;
  773.     if (Dottoslash) {        /* change . to . */
  774.         for (p=name; *p; ++p) {
  775.             if (*p == '/')
  776.                 q = p;
  777.             else if (*p == '.')
  778.                 *(q=p) = '/';
  779.         }
  780.         if (q && strlen(++q) > 8) {    /* If name>8 chars */
  781.             q += 8;            /*   make it .ext */
  782.             strcpy(name2, q);    /* save excess of name */
  783.             *q = '.';
  784.             strcpy(++q, name2);    /* add it back */
  785.         }
  786.     }
  787.  
  788.     for (p=name, q=txbuf ; *p; )
  789.         if ((*q++ = *p++) == '/' && !Fullname)
  790.             q = txbuf;
  791.     *q++ = 0;
  792.     p=q;
  793.     while (q < (txbuf + 1024))
  794.         *q++ = 0;
  795.     if (*name) {
  796. #ifdef XX
  797.         if (Thisflen >= 0) {
  798.             sprintf(p, "%u 0 0 0 %d %ld",
  799.               Thisflen, Filesleft, Totalleft);
  800.             Totalleft -= Thisflen;
  801.         }
  802. #endif
  803. #ifdef GENIE
  804.         else
  805.             sprintf(p, "%d", fdes.current_file_size * 1260);
  806.         vfile("%s open Binfile=%d size=%ld", name, Binfile,
  807.           fdes.current_file_size * 1260);
  808. #endif
  809.  
  810. #ifdef STAT
  811. #ifndef XX
  812.         if (fstat(fileno(in), &f)!= -1)
  813.             sprintf(p, "%lu %lo %o 0 %d %ld", f.st_size, f.st_mtime,
  814.               f.st_mode, Filesleft, Totalleft);
  815.         Totalleft -= f.st_size;
  816. #endif
  817. #endif
  818.  
  819.     }
  820.     if (--Filesleft <= 0)
  821.         Totalleft = 0;
  822.     if (Totalleft < 0)
  823.         Totalleft = 0;
  824.  
  825. #ifdef STAT
  826.     /* force 1k blocks if name won't fit in 128 byte block */
  827.     if (txbuf[125])
  828.         blklen=1024;
  829.     else {        /* A little goodie for IMP/KMD */
  830.         txbuf[127] = (f.st_size + 127) >>7;
  831.         txbuf[126] = (f.st_size + 127) >>15;
  832.     }
  833. #endif
  834.     if (Zmodem)
  835.         return zsendfile(txbuf, 1+strlen(p)+(p-txbuf));
  836.     if (wcputsec(txbuf, 0, 128)==ERROR)
  837.         return ERROR;
  838.     return OK;
  839. }
  840.  
  841. getnak()
  842. {
  843.     register firstch;
  844.  
  845.     Lastrx = 0;
  846.     for (;;) {
  847.         switch (firstch = readline(800)) {
  848.         case ZPAD:
  849.             if (getzrxinit())
  850.                 return ERROR;
  851.             Ascii = 0;    /* Receiver does the conversion */
  852.             return FALSE;
  853.         case TIMEOUT:
  854.             zperr("Timeout on pathname");
  855.             return TRUE;
  856.         case WANTG:
  857. #ifdef MODE2OK
  858.             mode(2);    /* Set cbreak, XON/XOFF, etc. */
  859. #endif
  860.             Optiong = TRUE;
  861.             blklen=1024;
  862.         case WANTCRC:
  863.             Crcflg = TRUE;
  864.         case NAK:
  865.             return FALSE;
  866.         case CAN:
  867.             if ((firstch = readline(20)) == CAN && Lastrx == CAN)
  868.                 return TRUE;
  869.         default:
  870.             break;
  871.         }
  872.         Lastrx = firstch;
  873.     }
  874. }
  875.  
  876.  
  877. wctx(flen)
  878. long flen;
  879. {
  880.     register int thisblklen;
  881.     register int sectnum, attempts, firstch;
  882.     long charssent;
  883.  
  884.     charssent = 0;  firstsec=TRUE;  thisblklen = blklen;
  885.     vfile("wctx:file length=%ld", flen);
  886.  
  887.     while ((firstch=readline(Rxtimeout))!=NAK && firstch != WANTCRC
  888.       && firstch != WANTG && firstch!=TIMEOUT && firstch!=CAN)
  889.         ;
  890.     if (firstch==CAN) {
  891.         zperr("Receiver CANcelled");
  892.         return ERROR;
  893.     }
  894.     if (firstch==WANTCRC)
  895.         Crcflg=TRUE;
  896.     if (firstch==WANTG)
  897.         Crcflg=TRUE;
  898.     sectnum=0;
  899.     for (;;) {
  900.         if (flen <= (charssent + 896L))
  901.             thisblklen = 128;
  902.         if ( !filbuf(txbuf, thisblklen))
  903.             break;
  904.         if (wcputsec(txbuf, ++sectnum, thisblklen)==ERROR)
  905.             return ERROR;
  906.         charssent += thisblklen;
  907.     }
  908.     fclose(in);
  909.     attempts=0;
  910.     do {
  911.         purgeline();
  912.         sendline(EOT);
  913.         flushmo();
  914.         ++attempts;
  915.     }
  916.         while ((firstch=(readline(Rxtimeout)) != ACK) && attempts < RETRYMAX);
  917.     if (attempts == RETRYMAX) {
  918.         zperr("No ACK on EOT");
  919.         return ERROR;
  920.     }
  921.     else
  922.         return OK;
  923. }
  924.  
  925. wcputsec(buf, sectnum, cseclen)
  926. char *buf;
  927. int sectnum;
  928. int cseclen;    /* data length of this sector to send */
  929. {
  930.     register checksum, wcj;
  931.     register char *cp;
  932.     unsigned oldcrc;
  933.     int firstch;
  934.     int attempts;
  935.  
  936.     firstch=0;    /* part of logic to detect CAN CAN */
  937.  
  938.     if (Verbose>2)
  939.         fprintf(stderr, "Sector %3d %2dk\n", Totsecs, Totsecs/8 );
  940.     else if (Verbose>1)
  941.         fprintf(stderr, "\rSector %3d %2dk ", Totsecs, Totsecs/8 );
  942.     for (attempts=0; attempts <= RETRYMAX; attempts++) {
  943.         Lastrx= firstch;
  944.         sendline(cseclen==1024?STX:SOH);
  945.         sendline(sectnum);
  946.         sendline(-sectnum -1);
  947.         oldcrc=checksum=0;
  948.         for (wcj=cseclen,cp=buf; --wcj>=0; ) {
  949.             sendline(*cp);
  950.             oldcrc=updcrc((0377& *cp), oldcrc);
  951.             checksum += *cp++;
  952.         }
  953.         if (Crcflg) {
  954.             oldcrc=updcrc(0,updcrc(0,oldcrc));
  955.             sendline((int)oldcrc>>8);
  956.             sendline((int)oldcrc);
  957.         }
  958.         else
  959.             sendline(checksum);
  960.         flushmo();
  961.  
  962.         if (Optiong) {
  963.             firstsec = FALSE; return OK;
  964.         }
  965.         firstch = readline(Rxtimeout);
  966. gotnak:
  967.         switch (firstch) {
  968.         case CAN:
  969.             if(Lastrx == CAN) {
  970. cancan:
  971.                 zperr("Cancelled");  return ERROR;
  972.             }
  973.             break;
  974.         case TIMEOUT:
  975.             zperr("Timeout on sector ACK"); continue;
  976.         case WANTCRC:
  977.             if (firstsec)
  978.                 Crcflg = TRUE;
  979.         case NAK:
  980.             zperr("NAK on sector"); continue;
  981.         case ACK: 
  982.             firstsec=FALSE;
  983.             Totsecs += (cseclen>>7);
  984.             return OK;
  985.         case ERROR:
  986.             zperr("Got burst for sector ACK"); break;
  987.         default:
  988.             zperr("Got %02x for sector ACK", firstch); break;
  989.         }
  990.         for (;;) {
  991.             Lastrx = firstch;
  992.             if ((firstch = readline(Rxtimeout)) == TIMEOUT)
  993.                 break;
  994.             if (firstch == NAK || firstch == WANTCRC)
  995.                 goto gotnak;
  996.             if (firstch == CAN && Lastrx == CAN)
  997.                 goto cancan;
  998.         }
  999.     }
  1000.     zperr("Retry Count Exceeded");
  1001.     return ERROR;
  1002. }
  1003.  
  1004. /* fill buf with count chars padding with ^Z for CPM */
  1005. filbuf(buf, count)
  1006. register char *buf;
  1007. {
  1008.     register c, m;
  1009.  
  1010.     if ( !Ascii) {
  1011.         m = read(fileno(in), buf, count);
  1012.         if (m <= 0)
  1013.             return 0;
  1014.         while (m < count)
  1015.             buf[m++] = 032;
  1016.         return count;
  1017.     }
  1018.     m=count;
  1019.     if (Lfseen) {
  1020.         *buf++ = 012; --m; Lfseen = 0;
  1021.     }
  1022.     while ((c=getc(in))!=EOF) {
  1023.         if (c == 012) {
  1024.             *buf++ = 015;
  1025.             if (--m == 0) {
  1026.                 Lfseen = TRUE; break;
  1027.             }
  1028.         }
  1029.         *buf++ =c;
  1030.         if (--m == 0)
  1031.             break;
  1032.     }
  1033.     if (m==count)
  1034.         return 0;
  1035.     else
  1036.         while (--m>=0)
  1037.             *buf++ = CPMEOF;
  1038.     return count;
  1039. }
  1040.  
  1041. /* Fill buffer with blklen chars */
  1042. zfilbuf()
  1043. {
  1044.     int n;
  1045.  
  1046. #ifdef TXBSIZE
  1047.     vfile("zfilbuf: bytcnt =%lu vpos=%lu blklen=%d", bytcnt, vpos, blklen);
  1048.     /* We assume request is within buffer, or just beyond */
  1049.     txbuf = Txb + (bytcnt & TXBMASK);
  1050.     if (vpos <= bytcnt) {
  1051. #ifdef GENIE
  1052.         if (Binfile) {
  1053.             long l, m;  char *p;
  1054.  
  1055.             for (p=txbuf, n=0, l=blklen;  l;  l -= 128, p+= 128) {
  1056.                 n += m = fgetb(p, 128, in);
  1057.                 if (m == 0)
  1058.                     break;
  1059.             }
  1060.         } else
  1061. #endif
  1062.         n = fread(txbuf, 1, blklen, in);
  1063.  
  1064.         vpos += n;
  1065.         if (n < blklen)
  1066.             Eofseen = 1;
  1067.         vfile("zfilbuf: n=%d vpos=%lu Eofseen=%d", n, vpos, Eofseen);
  1068.         return n;
  1069.     }
  1070.     if (vpos >= (bytcnt+blklen))
  1071.         return blklen;
  1072.     /* May be a short block if crash recovery etc. */
  1073.     Eofseen = BEofseen;
  1074.     return (vpos - bytcnt);
  1075. #else
  1076.     n = fread(txbuf, 1, blklen, in);
  1077.     if (n < blklen)
  1078.         Eofseen = 1;
  1079.     return n;
  1080. #endif
  1081. }
  1082.  
  1083. #ifdef TXBSIZE
  1084. /* Replacement for brain damaged fseek function.  Returns 0==success */
  1085. fooseek(fptr, pos, whence)
  1086. FILE *fptr;
  1087. long pos;
  1088. {
  1089.     long m, n;
  1090. #ifdef GENIE
  1091.     long l, k;  char *p;
  1092. #endif
  1093.  
  1094.     vfile("fooseek: pos =%lu vpos=%lu Canseek=%d", pos, vpos, Canseek);
  1095.     /* Seek offset < current buffer */
  1096.     if (pos < (vpos -TXBSIZE +1024)) {
  1097.         BEofseen = 0;
  1098.         if (Canseek > 0) {
  1099.             vpos = pos & ~TXBMASK;
  1100.             if (vpos >= pos)
  1101.                 vpos -= TXBSIZE;
  1102.             if (fseek(fptr, vpos, 0))
  1103.                 return 1;
  1104.         }
  1105.         else if (Canseek == 0) {
  1106. #ifdef GENIE
  1107.             if (Binfile) {
  1108.                 if (fseekb(fptr, vpos = 0L, 0))
  1109.                     return 1;
  1110.                 } else
  1111. #endif
  1112.             if (fseek(fptr, vpos = 0L, 0))
  1113.                 return 1;
  1114.         } else
  1115.             return 1;
  1116.         while (vpos < pos) {
  1117. #ifdef GENIE
  1118.             if (Binfile) {
  1119.                 for (p=Txb,n=0,l=TXBSIZE; l; l -= 128,p+= 128) {
  1120.                     n += (k = fgetb(p, 128, fptr));
  1121.                     vfile("bsk1: l=%d k=%d", l, k);
  1122.                     if (k == 0)
  1123.                         break;
  1124.                 }
  1125.             } else
  1126. #endif
  1127.             n = fread(Txb, 1, TXBSIZE, fptr);
  1128.             vpos += n;
  1129.             vfile("n=%d vpos=%ld", n, vpos);
  1130.             if (n < TXBSIZE) {
  1131.                 BEofseen = 1;
  1132.                 break;
  1133.             }
  1134.         }
  1135.         vfile("vpos=%ld", vpos);
  1136.         return 0;
  1137.     }
  1138.     /* Seek offset > current buffer (Crash Recovery, etc.) */
  1139.     if (pos > vpos) {
  1140.         if (Canseek)
  1141.             if (fseek(fptr, vpos = (pos & ~TXBMASK), 0))
  1142.                 return 1;
  1143.         while (vpos <= pos) {
  1144.             txbuf = Txb + (vpos & TXBMASK);
  1145.             m = TXBSIZE - (vpos & TXBMASK);
  1146.             vfile("m=%ld vpos=%ld", m,vpos);
  1147. #ifdef GENIE
  1148.             if (Binfile) {
  1149.                 for (p=txbuf,n=0,l=m; l; l -= 128,p+= 128) {
  1150.                     n += (k = fgetb(p, 128, fptr));
  1151.                     vfile("bsk2: l=%d k=%d n=%d", l, k, n);
  1152.                     if (k == 0)
  1153.                         break;
  1154.                 }
  1155.             } else
  1156. #endif
  1157.                 n = fread(txbuf, 1, m, fptr);
  1158.             vfile("n=%ld vpos=%ld", n,vpos);
  1159.             vpos += n;
  1160.             vfile("bo=%d m=%ld vpos=%ld", txbuf-Txb,m,vpos);
  1161.             if (n < m) {
  1162.                 BEofseen = 1;
  1163.                 break;
  1164.             }
  1165.         }
  1166.         return 0;
  1167.     }
  1168.     /* Seek offset is within current buffer */
  1169.     vfile("within buffer: vpos=%ld", vpos);
  1170.     return 0;
  1171. }
  1172. #define fseek fooseek
  1173. #endif
  1174.  
  1175.  
  1176. /* VARARGS1 */
  1177. vfile(f, a, b, c, d)
  1178. register char *f;
  1179. {
  1180.     if (Verbose > 2) {
  1181.         fprintf(stderr, f, a, b, c, d);
  1182.         fprintf(stderr, "\n");
  1183.     }
  1184. }
  1185.  
  1186.  
  1187. alrm()
  1188. {
  1189.     longjmp(tohere, -1);
  1190. }
  1191.  
  1192.  
  1193. #ifndef GENIE
  1194. #ifndef vax11c
  1195. /*
  1196.  * readline(timeout) reads character(s) from file descriptor 0
  1197.  * timeout is in tenths of seconds
  1198.  */
  1199. readline(timeout)
  1200. {
  1201.     register int c;
  1202.     static char byt[1];
  1203.  
  1204.     fflush(stdout);
  1205.     if (setjmp(tohere)) {
  1206.         zperr("TIMEOUT");
  1207.         return TIMEOUT;
  1208.     }
  1209.     c = timeout/10;
  1210.     if (c<2)
  1211.         c=2;
  1212.     if (Verbose>5) {
  1213.         fprintf(stderr, "Timeout=%d Calling alarm(%d) ", timeout, c);
  1214.     }
  1215.     signal(SIGALRM, alrm); alarm(c);
  1216.     c=read(0, byt, 1);
  1217.     alarm(0);
  1218.     if (Verbose>5)
  1219.         fprintf(stderr, "ret %x\n", byt[0]);
  1220.     if (c<1)
  1221.         return TIMEOUT;
  1222.     return (byt[0]&0377);
  1223. }
  1224.  
  1225. flushmo()
  1226. {
  1227.     fflush(stdout);
  1228. }
  1229.  
  1230.  
  1231. purgeline()
  1232. {
  1233. #ifdef USG
  1234.     ioctl(0, TCFLSH, 0);
  1235. #else
  1236.     lseek(0, 0L, 2);
  1237. #endif
  1238. }
  1239. #endif
  1240. #endif
  1241.  
  1242. /* send cancel string to get the other end to shut up */
  1243. canit()
  1244. {
  1245.     static char canistr[] = {
  1246.      24,24,24,24,24,24,24,24,24,24,8,8,8,8,8,8,8,8,8,8,0
  1247.     };
  1248.  
  1249. #ifdef vax11c
  1250.     raw_wbuf(strlen(canistr), canistr);
  1251.     purgeline();
  1252. #else
  1253.     printf(canistr);
  1254.     fflush(stdout);
  1255. #endif
  1256. }
  1257.  
  1258.  
  1259. /*
  1260.  * Log an error
  1261.  */
  1262. /*VARARGS1*/
  1263. zperr(s,p,u)
  1264. char *s, *p, *u;
  1265. {
  1266.     if (Verbose <= 0)
  1267.         return;
  1268.     fprintf(stderr, "Retry %d: ", errors);
  1269.     fprintf(stderr, s, p, u);
  1270.     fprintf(stderr, "\n");
  1271. }
  1272.  
  1273. /*
  1274.  * substr(string, token) searches for token in string s
  1275.  * returns pointer to token within string if found, NULL otherwise
  1276.  */
  1277. char *
  1278. substr(s, t)
  1279. register char *s,*t;
  1280. {
  1281.     register char *ss,*tt;
  1282.     /* search for first char of token */
  1283.     for (ss=s; *s; s++)
  1284.         if (*s == *t)
  1285.             /* compare token with substring */
  1286.             for (ss=s,tt=t; ;) {
  1287.                 if (*tt == 0)
  1288.                     return s;
  1289.                 if (*ss++ != *tt++)
  1290.                     break;
  1291.             }
  1292.     return NULL;
  1293. }
  1294.  
  1295. char *babble[] = {
  1296. #ifdef vax11c
  1297.     "Send file(s) with ZMODEM/YMODEM/XMODEM Protocol",
  1298.     "    (Y) = Option applies to YMODEM only",
  1299.     "    (Z) = Option applies to ZMODEM only",
  1300.     "Usage:    sz [-2+abdefkLlNnquvwYy] [-] file ...",
  1301.     "    sz [-2Ceqv] -c COMMAND",
  1302.     "    \\ Force next option letter to upper case",
  1303.     "    sb [-2adfkquv] [-] file ...",
  1304.     "    sx [-2akquv] [-] file",
  1305. #endif
  1306. #ifndef vax11c
  1307.     "Send file(s) with ZMODEM/YMODEM/XMODEM Protocol",
  1308.     "    (Y) = Option applies to YMODEM only",
  1309.     "    (Z) = Option applies to ZMODEM only",
  1310.     "Usage:    sz [-2+abdefkLlNnquvwYy] [-] file ...",
  1311.     "    sz [-2Ceqv] -c COMMAND",
  1312.     "    sb [-2adfkquv] [-] file ...",
  1313.     "    sx [-2akquv] [-] file",
  1314. #endif
  1315. #ifdef CSTOPB
  1316.     "    2   Use 2 stop bits",
  1317. #endif
  1318.     "    +   Append to existing destination file (Z)",
  1319.     "    a   (ASCII) change NL to CR/LF",
  1320.     "    b   Binary file transfer override",
  1321.     "    c   send COMMAND (Z)",
  1322. #ifndef vax11c
  1323.     "    d   Change '.' to '/' in pathnames (Y/Z)",
  1324. #endif
  1325.     "    e   Escape all control characters (Z)",
  1326.     "    f   send Full pathname (Y/Z)",
  1327.     "    i   send COMMAND, ack Immediately (Z)",
  1328.     "    k   Send 1024 byte packets (Y)",
  1329.     "    L N Limit subpacket length to N bytes (Z)",
  1330.     "    l N Limit frame length to N bytes (l>=L) (Z)",
  1331.     "    n   send file only if source newer (Z)",
  1332.     "    N   send file only if source newer or longer (Z)",
  1333.     "    o   Use 16 bit CRC instead of 32 bit CRC (Z)",
  1334.     "    p   Protect existing destination file (Z)",
  1335.     "    r   Resume/Recover interrupted file transfer (Z)",
  1336.     "    q   Quiet (no progress reports)",
  1337. #ifndef vax11c
  1338.     "    u   Unlink (remove) file after transmission",
  1339. #endif
  1340.     "    v   Verbose - provide debugging information",
  1341.     "    w N restrict Window to N bytes (Z)",
  1342.     "    Y   Yes, overwrite existing file, skip if not present at rx (Z)",
  1343.     "    y   Yes, overwrite existing file (Z)",
  1344.     "    Z   Activate ZMODEM compression(Z)",
  1345.     ""
  1346. };
  1347.  
  1348. usage()
  1349. {
  1350.     char **pp;
  1351.  
  1352.     for (pp=babble; **pp; ++pp)
  1353.         fprintf(stderr, "%s\n", *pp);
  1354.     fprintf(stderr, "%s for %s by Chuck Forsberg, Omen Technology INC\n",
  1355.      VERSION, OS);
  1356.     fprintf(stderr, "\t\t\042The High Reliability Software\042\n");
  1357.     cucheck();
  1358.     exit(SS_NORMAL);
  1359. }
  1360.  
  1361. /*
  1362.  * Get the receiver's init parameters
  1363.  */
  1364. getzrxinit()
  1365. {
  1366.     register n;
  1367. #ifdef STAT
  1368.     struct stat f;
  1369. #endif
  1370.  
  1371.     for (n=10; --n>=0; ) {
  1372.         
  1373.         switch (zgethdr(Rxhdr, 1)) {
  1374.         case ZCHALLENGE:    /* Echo receiver's challenge numbr */
  1375.             stohdr(Rxpos);
  1376.             zshhdr(4, ZACK, Txhdr);
  1377.             continue;
  1378.         case ZCOMMAND:        /* They didn't see out ZRQINIT */
  1379.             stohdr(0L);
  1380.             zshhdr(4, ZRQINIT, Txhdr);
  1381.             continue;
  1382.         case ZRINIT:
  1383.             Rxflags = 0377 & Rxhdr[ZF0];
  1384.             Usevhdrs = Rxhdr[ZF1] & CANVHDR;
  1385.             Txfcs32 = (Wantfcs32 && (Rxflags & CANFC32));
  1386.             Zctlesc |= Rxflags & TESCCTL;
  1387.             Rxbuflen = (0377 & Rxhdr[ZP0])+((0377 & Rxhdr[ZP1])<<8);
  1388.             if ( !(Rxflags & CANFDX))
  1389.                 Txwindow = 0;
  1390.             vfile("Rxbuflen=%d Tframlen=%d", Rxbuflen, Tframlen);
  1391.             if ( !Fromcu)
  1392.                 signal(SIGINT, SIG_IGN);
  1393. #ifdef MODE2OK
  1394.             mode(2);    /* Set cbreak, XON/XOFF, etc. */
  1395. #endif
  1396.  
  1397. #ifndef READCHECK
  1398. #ifndef USG
  1399. #ifndef GENIE
  1400.             /* Use 1024 byte frames if no sample/interrupt */
  1401.             if (Rxbuflen < 32 || Rxbuflen > 1024) {
  1402.                 Rxbuflen = 1024;
  1403.                 vfile("Rxbuflen=%d", Rxbuflen);
  1404.             }
  1405. #endif
  1406. #endif
  1407. #endif
  1408.  
  1409.             /* Override to force shorter frame length */
  1410.             if (Rxbuflen && (Rxbuflen>Tframlen) && (Tframlen>=32))
  1411.                 Rxbuflen = Tframlen;
  1412.             if ( !Rxbuflen && (Tframlen>=32) && (Tframlen<=1024))
  1413.                 Rxbuflen = Tframlen;
  1414.             vfile("Rxbuflen=%d", Rxbuflen);
  1415.  
  1416. #ifndef GENIE
  1417. #ifndef vax11c
  1418. #ifdef STAT
  1419.             /* If using a pipe for testing set lower buf len */
  1420.             fstat(0, &f);
  1421.             if ((f.st_mode & S_IFMT) != S_IFCHR) {
  1422.                 Rxbuflen = 1024;
  1423.             }
  1424. #endif
  1425. #endif
  1426. #endif
  1427.  
  1428. #ifdef BADSEEK
  1429. #ifdef GENIE
  1430.             if (Txwindow == 0) {
  1431.                 Txwspac = (Txwindow = 4096)/4;
  1432.             }
  1433. #else
  1434.             if (Txwindow == 0)
  1435.                 Txwindow = TXBSIZE - 1024;
  1436.             Txwspac = TXBSIZE/4;
  1437. #endif
  1438.             Canseek = 0;
  1439. #endif
  1440.  
  1441.             /*
  1442.              * If input is not a regular file, force ACK's to
  1443.              *  prevent running beyond the buffer limits
  1444.              */
  1445. #ifdef STAT
  1446.             if ( !Command) {
  1447.                 fstat(fileno(in), &f);
  1448.                 if ((f.st_mode & S_IFMT) != S_IFREG) {
  1449.                     Canseek = -1;
  1450. #ifdef TXBSIZE
  1451.                     Txwindow = TXBSIZE - 1024;
  1452.                     Txwspac = TXBSIZE/4;
  1453. #else
  1454.                     return ERROR;
  1455. #endif
  1456.                 }
  1457.             }
  1458. #endif
  1459.  
  1460.             /* Set initial subpacket length */
  1461.             if (blklen < 1024) {    /* Command line override? */
  1462.                 if (Effbaud > 300)
  1463.                     blklen = 256;
  1464.                 if (Effbaud > 1200)
  1465.                     blklen = 512;
  1466.                 if (Effbaud > 2400)
  1467.                     blklen = 1024;
  1468.             }
  1469.             if (Rxbuflen && blklen>Rxbuflen)
  1470.                 blklen = Rxbuflen;
  1471.             if (blkopt && blklen > blkopt)
  1472.                 blklen = blkopt;
  1473. #ifdef GENIE
  1474.             blklen /= 128;  blklen *= 128;
  1475.             if (blklen < 128)
  1476.                 blklen = 128;
  1477. #endif
  1478.             vfile("Rxbuflen=%d blklen=%d", Rxbuflen, blklen);
  1479.             vfile("Txwindow = %u Txwspac = %d", Txwindow, Txwspac);
  1480.  
  1481.  
  1482.             if (Lztrans == ZTRLE && (Rxflags & CANRLE))
  1483.                 Txfcs32 = 2;
  1484.             else
  1485.                 Lztrans = 0;
  1486.  
  1487.             return (sendzsinit());
  1488.         case ZCAN:
  1489.         case TIMEOUT:
  1490.             return ERROR;
  1491.         case ZRQINIT:
  1492.             if (Rxhdr[ZF0] == ZCOMMAND)
  1493.                 continue;
  1494.         default:
  1495.             zshhdr(4, ZNAK, Txhdr);
  1496.             continue;
  1497.         }
  1498.     }
  1499.     return ERROR;
  1500. }
  1501.  
  1502. /* Send send-init information */
  1503. sendzsinit()
  1504. {
  1505.     register c;
  1506.  
  1507.     if (Myattn[0] == '\0' && (!Zctlesc || (Rxflags & TESCCTL)))
  1508.         return OK;
  1509.     errors = 0;
  1510.     for (;;) {
  1511.         stohdr(0L);
  1512. #ifdef ALTCANOFF
  1513.         Txhdr[ALTCOFF] = ALTCANOFF;
  1514. #endif
  1515.         if (Zctlesc) {
  1516.             Txhdr[ZF0] |= TESCCTL; zshhdr(4, ZSINIT, Txhdr);
  1517.         }
  1518.         else
  1519.             zsbhdr(4, ZSINIT, Txhdr);
  1520.         zsdata(Myattn, ZATTNLEN, ZCRCW);
  1521.         c = zgethdr(Rxhdr, 1);
  1522.         switch (c) {
  1523.         case ZCAN:
  1524.             return ERROR;
  1525.         case ZACK:
  1526.             return OK;
  1527.         default:
  1528.             if (++errors > 19)
  1529.                 return ERROR;
  1530.             continue;
  1531.         }
  1532.     }
  1533. }
  1534.  
  1535. /* Send file name and related info */
  1536. zsendfile(buf, blen)
  1537. char *buf;
  1538. {
  1539.     register c;
  1540.     register UNSL long crc;
  1541.     long lastcrcrq = -1;
  1542.     char *p;
  1543.  
  1544.     for (;;) {
  1545.         Txhdr[ZF0] = Lzconv;    /* file conversion request */
  1546.         Txhdr[ZF1] = Lzmanag;    /* file management request */
  1547.         if (Lskipnocor)
  1548.             Txhdr[ZF1] |= ZMSKNOLOC;
  1549.         Txhdr[ZF2] = Lztrans;    /* file transport request */
  1550.         Txhdr[ZF3] = 0;
  1551.         zsbhdr(4, ZFILE, Txhdr);
  1552.         zsdata(buf, blen, ZCRCW);
  1553. again:
  1554.         c = zgethdr(Rxhdr, 1);
  1555.         switch (c) {
  1556.         case ZRINIT:
  1557.             while ((c = readline(50)) > 0)
  1558.                 if (c == ZPAD) {
  1559.                     goto again;
  1560.                 }
  1561.             /* **** FALL THRU TO **** */
  1562.         default:
  1563.             continue;
  1564.         case ZCAN:
  1565.         case TIMEOUT:
  1566.         case ZABORT:
  1567.         case ZFIN:
  1568.             return ERROR;
  1569.         case ZCRC:
  1570.             if (Rxpos != lastcrcrq) {
  1571.                 lastcrcrq = Rxpos;
  1572.                 crc = 0xFFFFFFFFL;
  1573.                 if (Canseek >= 0) {
  1574.                     fseek(in, 0L, 0);
  1575.                     while (((c = getc(in)) != EOF) && --lastcrcrq)
  1576.                         crc = UPDC32(c, crc);
  1577.                     crc = ~crc;
  1578.                     clearerr(in);    /* Clear possible EOF */
  1579.                     lastcrcrq = Rxpos;
  1580.                 }
  1581.             }
  1582.             stohdr(crc);
  1583.             zsbhdr(4, ZCRC, Txhdr);
  1584.             goto again;
  1585.         case ZSKIP:
  1586.             fclose(in); return c;
  1587.         case ZRPOS:
  1588.             /*
  1589.              * Suppress zcrcw request otherwise triggered by
  1590.              * lastyunc==bytcnt
  1591.              */
  1592. #ifdef GENIE
  1593.             /*
  1594.              *  Special case - turn on RLE if not archive, etc.
  1595.              *   otherwise turn off RLE unless cmd line specified
  1596.              */
  1597.             if (Rxflags & CANRLE) {        /* RX can do it */
  1598.                 bytcnt = 0;
  1599.                 zfilbuf();
  1600.                 vfile("txbuf012: %x %x %x", txbuf[0], txbuf[1],
  1601.                   txbuf[2]);
  1602.                 if ((txbuf[0] != 032)    /* .ARC file */
  1603.                  && (txbuf[0] != 0x1f)    /* .Z file */
  1604.                  && (txbuf[0] != 0x1c)    /* .LHZ file */
  1605.                  && strncmp(txbuf, "ZOO", 3)
  1606.                  && strncmp(txbuf, "GIF", 3)
  1607.                  && (txbuf[2] != 3))    /* .ZIP file */
  1608.                     Txfcs32 = 2;
  1609.                 else if ( !(Lztrans & ZTRLE))
  1610.                     Txfcs32 = 1;
  1611.             }
  1612.             /* GEnie binary can't seek to byte */
  1613.             if (Binfile) {
  1614.                 Rxpos &= ~127L;
  1615.             }
  1616. #endif
  1617.             if (fseek(in, Rxpos, 0))
  1618.                 return ERROR;
  1619.             Lastsync = (bytcnt = Txpos = Lrxpos = Rxpos) -1;
  1620.             return zsendfdata();
  1621.         }
  1622.     }
  1623. }
  1624.  
  1625. /* Send the data in the file */
  1626. zsendfdata()
  1627. {
  1628.     register c, e, n;
  1629.     register newcnt;
  1630.     register long tcount = 0;
  1631.     int junkcount;        /* Counts garbage chars received by TX */
  1632.     static int tleft = 6;    /* Counter for test mode */
  1633.  
  1634.     junkcount = 0;
  1635.     Beenhereb4 = FALSE;
  1636. somemore:
  1637.     if (setjmp(intrjmp)) {
  1638. waitack:
  1639.         junkcount = 0;
  1640.         c = getinsync(0);
  1641. gotack:
  1642.         switch (c) {
  1643.         default:
  1644.         case ZCAN:
  1645.             fclose(in);
  1646.             return ERROR;
  1647.         case ZSKIP:
  1648.             fclose(in);
  1649.             return c;
  1650.         case ZACK:
  1651.         case ZRPOS:
  1652.             break;
  1653.         case ZRINIT:
  1654.             return OK;
  1655.         }
  1656. #ifdef READCHECK
  1657.         /*
  1658.          * If the reverse channel can be tested for data,
  1659.          *  this logic may be used to detect error packets
  1660.          *  sent by the receiver, in place of setjmp/longjmp
  1661.          *  rdchk(fd) returns non 0 if a character is available
  1662.          */
  1663.         while (rdchk(0)) {
  1664. #ifdef EATSIT
  1665.             switch (checked)
  1666. #else
  1667.             switch (readline(1))
  1668. #endif
  1669.             {
  1670.             case CAN:
  1671.             case ZPAD:
  1672.                 c = getinsync(1);
  1673.                 goto gotack;
  1674.             case XOFF:        /* Wait a while for an XON */
  1675.             case XOFF|0200:
  1676.                 readline(100);
  1677.             }
  1678.         }
  1679. #endif
  1680.     }
  1681.  
  1682.     if ( !Fromcu)
  1683.         signal(SIGINT, onintr);
  1684.     newcnt = Rxbuflen;
  1685.     Txwcnt = 0;
  1686.     stohdr(Txpos);
  1687.     zsbhdr(4, ZDATA, Txhdr);
  1688.  
  1689.     /*
  1690.      * Special testing mode.  This should force receiver to Attn,ZRPOS
  1691.      *  many times.  Each time the signal should be caught, causing the
  1692.      *  file to be started over from the beginning.
  1693.      */
  1694.     if (Test) {
  1695.         if ( --tleft)
  1696.             while (tcount < 20000) {
  1697.                 printf(qbf); fflush(stdout);
  1698.                 tcount += strlen(qbf);
  1699. #ifdef READCHECK
  1700.                 while (rdchk(0)) {
  1701. #ifdef EATSIT
  1702.                     switch (checked)
  1703. #else
  1704.                     switch (readline(1))
  1705. #endif
  1706.                     {
  1707.                     case CAN:
  1708.                     case ZPAD:
  1709. #ifdef TCFLSH
  1710.                         ioctl(0, TCFLSH, 1);
  1711. #endif
  1712.                         goto waitack;
  1713.                     case XOFF:    /* Wait for XON */
  1714.                     case XOFF|0200:
  1715.                         readline(100);
  1716.                     }
  1717.                 }
  1718. #endif
  1719.             }
  1720.         signal(SIGINT, SIG_IGN); canit();
  1721.         sleep(3); purgeline(); mode(0);
  1722.         printf("\nsz: Tcount = %ld\n", tcount);
  1723.         if (tleft) {
  1724.             printf("ERROR: Interrupts Not Caught\n");
  1725.             exit(1);
  1726.         }
  1727.         exit(SS_NORMAL);
  1728.     }
  1729.  
  1730.     do {
  1731.         n = zfilbuf();
  1732.         if (Eofseen)
  1733.             e = ZCRCE;
  1734.         else if (junkcount > 3)
  1735.             e = ZCRCW;
  1736.         else if (bytcnt == Lastsync)
  1737.             e = ZCRCW;
  1738.         else if (Rxbuflen && (newcnt -= n) <= 0)
  1739.             e = ZCRCW;
  1740.         else if (Txwindow && (Txwcnt += n) >= Txwspac) {
  1741.             Txwcnt = 0;  e = ZCRCQ;
  1742.         } else
  1743.             e = ZCRCG;
  1744.         if (Verbose>1)
  1745.             fprintf(stderr, "\r%7ld ZMODEM%s    ",
  1746.               Txpos, Crc32t?" CRC-32":"");
  1747.         zsdata(txbuf, n, e);
  1748.         bytcnt = Txpos += n;
  1749.         if (e == ZCRCW)
  1750.             goto waitack;
  1751. #ifdef READCHECK
  1752.         /*
  1753.          * If the reverse channel can be tested for data,
  1754.          *  this logic may be used to detect error packets
  1755.          *  sent by the receiver, in place of setjmp/longjmp
  1756.          *  rdchk(fd) returns non 0 if a character is available
  1757.          */
  1758.         fflush(stdout);
  1759.         while (rdchk(0)) {
  1760. #ifdef EATSIT
  1761.             switch (checked)
  1762. #else
  1763.             switch (readline(1))
  1764. #endif
  1765.             {
  1766.             case CAN:
  1767.             case ZPAD:
  1768.                 c = getinsync(1);
  1769.                 if (c == ZACK)
  1770.                     break;
  1771. #ifdef TCFLSH
  1772.                 ioctl(0, TCFLSH, 1);
  1773. #endif
  1774.                 /* zcrce - dinna wanna starta ping-pong game */
  1775.                 zsdata(txbuf, 0, ZCRCE);
  1776.                 goto gotack;
  1777.             case XOFF:        /* Wait a while for an XON */
  1778.             case XOFF|0200:
  1779.                 readline(100);
  1780.             default:
  1781.                 ++junkcount;
  1782.             }
  1783.         }
  1784. #endif    /* READCHECK */
  1785.         if (Txwindow) {
  1786.             while ((tcount = (Txpos - Lrxpos)) >= Txwindow) {
  1787.                 vfile("%ld window >= %u", tcount, Txwindow);
  1788.                 if (e != ZCRCQ)
  1789.                     zsdata(txbuf, 0, e = ZCRCQ);
  1790.                 c = getinsync(1);
  1791.                 if (c != ZACK) {
  1792. #ifdef TCFLSH
  1793.                     ioctl(0, TCFLSH, 1);
  1794. #endif
  1795.                     zsdata(txbuf, 0, ZCRCE);
  1796.                     goto gotack;
  1797.                 }
  1798.             }
  1799.             vfile("window = %ld", tcount);
  1800.         }
  1801.     } while (!Eofseen);
  1802.     if ( !Fromcu)
  1803.         signal(SIGINT, SIG_IGN);
  1804.  
  1805.     for (;;) {
  1806.         stohdr(Txpos);
  1807.         zsbhdr(4, ZEOF, Txhdr);
  1808.         switch (getinsync(0)) {
  1809.         case ZACK:
  1810.             continue;
  1811.         case ZRPOS:
  1812.             goto somemore;
  1813.         case ZRINIT:
  1814.             return OK;
  1815.         case ZSKIP:
  1816.             fclose(in);
  1817.             return c;
  1818.         default:
  1819.             fclose(in);
  1820.             return ERROR;
  1821.         }
  1822.     }
  1823. }
  1824.  
  1825. /*
  1826.  * Respond to receiver's complaint, get back in sync with receiver
  1827.  */
  1828. getinsync(flag)
  1829. {
  1830.     register c;
  1831.  
  1832.     for (;;) {
  1833.         if (Test) {
  1834.             printf("\r\n\n\n***** Signal Caught *****\r\n");
  1835.             Rxpos = 0; c = ZRPOS;
  1836.         } else
  1837.             c = zgethdr(Rxhdr, 0);
  1838.         switch (c) {
  1839.         case ZCAN:
  1840.         case ZABORT:
  1841.         case ZFIN:
  1842.         case TIMEOUT:
  1843.             return ERROR;
  1844.         case ZRPOS:
  1845.             /* ************************************* */
  1846.             /*  If sending to a buffered modem, you  */
  1847.             /*   might send a break at this point to */
  1848.             /*   dump the modem's buffer.         */
  1849.             clearerr(in);    /* In case file EOF seen */
  1850.             if (fseek(in, Rxpos, 0))
  1851.                 return ERROR;
  1852.             Eofseen = 0;
  1853.             bytcnt = Lrxpos = Txpos = Rxpos;
  1854. #ifndef GENIE
  1855.             if (Lastsync == Rxpos) {
  1856.                 if (++Beenhereb4 > 4)
  1857.                     if (blklen > 32)
  1858.                         blklen /= 2;
  1859.             }
  1860. #endif
  1861.             Lastsync = Rxpos;
  1862.             return c;
  1863.         case ZACK:
  1864.             Lrxpos = Rxpos;
  1865.             if (flag || Txpos == Rxpos)
  1866.                 return ZACK;
  1867.             continue;
  1868.         case ZRINIT:
  1869.         case ZSKIP:
  1870.             fclose(in);
  1871.             return c;
  1872.         case ERROR:
  1873.         default:
  1874.             zsbhdr(4, ZNAK, Txhdr);
  1875.             continue;
  1876.         }
  1877.     }
  1878. }
  1879.  
  1880.  
  1881. /* Say "bibi" to the receiver, try to do it cleanly */
  1882. saybibi()
  1883. {
  1884.     for (;;) {
  1885.         stohdr(0L);        /* CAF Was zsbhdr - minor change */
  1886.         zshhdr(4, ZFIN, Txhdr);    /*  to make debugging easier */
  1887.         switch (zgethdr(Rxhdr, 0)) {
  1888.         case ZFIN:
  1889.             sendline('O'); sendline('O'); flushmo();
  1890.         case ZCAN:
  1891.         case TIMEOUT:
  1892.             return;
  1893.         }
  1894.     }
  1895. }
  1896.  
  1897. /* Local screen character display function */
  1898. bttyout(c)
  1899. {
  1900.     if (Verbose)
  1901.         putc(c, stderr);
  1902. }
  1903.  
  1904. /* Send command and related info */
  1905. zsendcmd(buf, blen)
  1906. char *buf;
  1907. {
  1908.     register c;
  1909.     long cmdnum;
  1910.  
  1911. #ifdef GENIE
  1912.     cmdnum = 69;
  1913. #else
  1914.     cmdnum = getpid();
  1915. #endif
  1916.     errors = 0;
  1917.     for (;;) {
  1918.         stohdr(cmdnum);
  1919.         Txhdr[ZF0] = Cmdack1;
  1920.         zsbhdr(4, ZCOMMAND, Txhdr);
  1921.         zsdata(buf, blen, ZCRCW);
  1922. listen:
  1923.         Rxtimeout = 100;        /* Ten second wait for resp. */
  1924.         Usevhdrs = 0;        /* Allow rx to send fixed len headers */
  1925.         c = zgethdr(Rxhdr, 1);
  1926.  
  1927.         switch (c) {
  1928.         case ZRINIT:
  1929.             goto listen;    /* CAF 8-21-87 */
  1930.         case ERROR:
  1931.         case GCOUNT:
  1932.         case TIMEOUT:
  1933.             if (++errors > Cmdtries)
  1934.                 return ERROR;
  1935.             continue;
  1936.         case ZCAN:
  1937.         case ZABORT:
  1938.         case ZFIN:
  1939.         case ZSKIP:
  1940.         case ZRPOS:
  1941.             return ERROR;
  1942.         default:
  1943.             if (++errors > 20)
  1944.                 return ERROR;
  1945.             continue;
  1946.         case ZCOMPL:
  1947.             Exitcode = Rxpos;
  1948.             saybibi();
  1949.             return OK;
  1950.         case ZRQINIT:
  1951. #ifdef vax11c        /* YAMP :== Yet Another Missing Primitive */
  1952.             return ERROR;
  1953. #else
  1954.             vfile("******** RZ *******");
  1955.             system("rz");
  1956.             vfile("******** SZ *******");
  1957.             goto listen;
  1958. #endif
  1959.         }
  1960.     }
  1961. }
  1962.  
  1963. /*
  1964.  * If called as sb use YMODEM protocol
  1965.  */
  1966. chkinvok(s)
  1967. char *s;
  1968. {
  1969.     register char *p;
  1970.  
  1971.     p = s;
  1972.     while (*p == '-')
  1973.         s = ++p;
  1974.     while (*p)
  1975.         if (*p++ == '/')
  1976.             s = p;
  1977.     if (*s == 'v') {
  1978.         Verbose=1; ++s;
  1979.     }
  1980.     Progname = s;
  1981.     if (s[0]=='s' && s[1]=='b') {
  1982.         Nozmodem = TRUE; blklen=1024;
  1983.     }
  1984.     if (s[0]=='s' && s[1]=='x') {
  1985.         Modem2 = TRUE;
  1986.     }
  1987. }
  1988.  
  1989. #ifdef STAT
  1990. countem(argc, argv)
  1991. register char **argv;
  1992. {
  1993.     register c;
  1994.     struct stat f;
  1995.  
  1996.     for (Totalleft = 0, Filesleft = 0; --argc >=0; ++argv) {
  1997.         f.st_size = -1;
  1998.         if (Verbose>2) {
  1999.             fprintf(stderr, "\nCountem: %03d %s ", argc, *argv);
  2000.             fflush(stderr);
  2001.         }
  2002.         if (access(*argv, 04) >= 0 && stat(*argv, &f) >= 0) {
  2003.             c = f.st_mode & S_IFMT;
  2004.             if (c != S_IFDIR && c != S_IFBLK) {
  2005.                 ++Filesleft;  Totalleft += f.st_size;
  2006.             }
  2007.         }
  2008.         if (Verbose>2)
  2009.             fprintf(stderr, " %ld", f.st_size);
  2010.     }
  2011.     if (Verbose>2)
  2012.         fprintf(stderr, "\ncountem: Total %d %ld\n",
  2013.           Filesleft, Totalleft);
  2014. }
  2015. #else
  2016. countem(argc, argv)
  2017. register char **argv;
  2018. {
  2019.     register c;
  2020.     register char *p;
  2021.     long size;
  2022.  
  2023.     for (Totalleft = 0, Filesleft = 0; --argc >=0; ++argv) {
  2024.         size = -1;
  2025.         if (Verbose>2) {
  2026.             fprintf(stderr, "\nCountem: %03d %s ", argc, *argv);
  2027.             fflush(stderr);
  2028.         }
  2029.         ++Filesleft;  
  2030. #ifdef XARGSFILE
  2031.         /* Look for file length in third colon sep field */
  2032.         for (p = *argv; *p; ++p) {
  2033.             if (*p == ':') {
  2034.                 for (++p; *p; ++p) {
  2035.                     if (*p == ':') {
  2036.                         ++p;
  2037.                         size = atol(p);
  2038.                         Totalleft += size;
  2039.                         break;
  2040.                     }
  2041.                 }
  2042.             break;
  2043.             }
  2044.         }
  2045. #endif
  2046.  
  2047.         if (Verbose>2)
  2048.             fprintf(stderr, " %ld", size);
  2049.     }
  2050.     if (Verbose>2)
  2051.         fprintf(stderr, "\ncountem: Total %d %ld\n",
  2052.           Filesleft, Totalleft);
  2053. }
  2054. #endif
  2055.  
  2056. chartest(m)
  2057. {
  2058.     register n;
  2059.  
  2060.     mode(m);
  2061.     printf("\r\n\nCharacter Transparency Test Mode %d\r\n", m);
  2062.     printf("If Pro-YAM/ZCOMM is not displaying ^M hit ALT-V NOW.\r\n");
  2063.     printf("Hit Enter.\021");  fflush(stdout);
  2064.     readline(500);
  2065.  
  2066.     for (n = 0; n < 256; ++n) {
  2067.         if (!(n%8))
  2068.             printf("\r\n");
  2069.         printf("%02x ", n);  fflush(stdout);
  2070.         sendline(n);    flushmo();
  2071.         printf("  ");  fflush(stdout);
  2072.         if (n == 127) {
  2073.             printf("Hit Enter.\021");  fflush(stdout);
  2074.             readline(500);
  2075.             printf("\r\n");  fflush(stdout);
  2076.         }
  2077.     }
  2078.     printf("\021\r\nEnter Characters, echo is in hex.\r\n");
  2079.     printf("Hit SPACE or pause 40 seconds for exit.\r\n");
  2080.  
  2081.     while (n != TIMEOUT && n != ' ') {
  2082.         n = readline(400);
  2083.         printf("%02x\r\n", n);
  2084.         fflush(stdout);
  2085.     }
  2086.     printf("\r\nMode %d character transparency test ends.\r\n", m);
  2087.     fflush(stdout);
  2088. }
  2089.  
  2090. /* End of sz.c */
  2091.